
def gen_digital_human(msg):
    print(f"[start processing]:{msg}")
    text_to_wav(msg)


def text_to_wav(text):
    print(f"[text_to_wav] start")
    from gtts import gTTS
    from pydub import AudioSegment
    import os
    import time
    # 使用 gTTS 将文本转换为 mp3 文件
    tts = gTTS(text=text, lang='en')  # 'en' 表示英语，可以根据需要更改
    mp3_file = "temp.mp3"
    tts.save(mp3_file)
    current_timestamp = int(time.time())
    output_file = f'{current_timestamp}.wav'
    # 使用 pydub 将 mp3 转换为 wav
    sound = AudioSegment.from_mp3(mp3_file)
    sound.export(output_file, format="wav")
    # 清理临时文件
    os.remove(mp3_file)
    script_path = "/Users/shuguang.wang/mycode/ai_community/SadTalker/william.sh"
    print(f"[text_to_wav] -> {output_file}")
    run_shell_script(script_path, output_file)



def run_shell_script(script_path, arg):
    # 直接执行shell脚本，并传入参数
    import os
    print(f"[digital_human] start ")
    os.system(f"bash {script_path} {arg}")


# gen_digital_human("你好啊， 我是王曙光")
